<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('Cust_CustomerInfoFormal.Add')" type="primary" icon="plus" @click="handleAdd()"
        >发起工单</a-button
      >

      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="客户名称" />
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24">
            <a-button
              type="primary"
              @click="
                () => {
                  this.pagination.current = 1
                }
              "
              >查询</a-button
            >
            <a-button style="margin-left: 8px" @click="Repossess">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <EditForm ref="edit" />
    <a-table
      ref="table"
      :scroll="{ y: 530 }"
      :columns="columns"
      :rowKey="(row) => row.cCusCode"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="true"
      size="small"
    >
    </a-table>
  </a-card>
</template>

<script>
import moment from 'moment'
import EditForm from './EditForm.vue'

const columns = [
  { title: '客户名称', dataIndex: 'cCusName', align: 'left' },

  { title: '类型', dataIndex: 'cCusBank', align: 'left' },
  { title: '费用', dataIndex: 'cCusAddress', ellipsis: true },
  { title: '业务员', dataIndex: 'salesman' },
  { title: '操作', dataIndex: 'action', align: 'left', scopedSlots: { customRender: 'action' } },
]

export default {
  components: { EditForm },

  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 },
      },
      data: [],
      pagination: {
        current: 1,
        pageSize: 25,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['25', '50', '100'], // 设置pageSize的可选值，页面可以通过下拉框进行选择
        showSizeChanger: true,
      },
      filters: {},
      entity: {},
      sorter: { field: 'cCusCode', order: 'desc' },

      queryParam: [{ condition: 'cCusCode' }],
      loading: false,
      columns,
      selectedRowKeys: [],
      selectedRows: [],
    }
  },
  methods: {
    handleAdd() {
      this.$refs.edit.openForm(null, '添加')
    },
    Repossess() {
      this.getDataList()
    },

    handleTableChange(pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      
      this.getDataList()
    },

    getDataList() {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/CustomerManagement/Customer/GetDataListByMoreCondition', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order,
          Search: this.queryParam,
          ...this.filters,
        })
        .then((resJson) => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    hasSelected() {
      return this.selectedRowKeys.length > 0
    },
    handleDelete(ids) {
      var thisObj = this
      this.$confirm({
        title: '确认删除吗?',
        onOk() {
          
        },
      })
    },
    timeFormat(val) {
      // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    },
  },
}
</script>
